<?php
 /*
  *总后台商家模型类
  */
namespace Home\Model; 
use Think\Model;
class ShopUserModel extends Model{
	public function index($arg=array())
		{
			$arg['keywords']=$arg['keywords'];
			$condition=' 1=1 ';
			if(!empty($arg['keywords']))
			{
				$condition.=" AND  companyname like '%{$arg['keywords']}%' OR  connectname like '%{$arg['keywords']}%' ";
			}
			
			$sql="select *, FROM_UNIXTIME(createtime, '%Y-%m-%d %H:%i:%S') as createtime from ".C(DB_PREFIX).'shop_user where'.$condition;
			
			$shops=M()->query($sql);

			$device=M('device');
			$yunying=M('yunying_user');
			if(!empty($shops))
			{
				foreach($shops as $key=>&$value)
				{
					$count=$device->where('shopid=%d',$value['shopid'])->count();
					$value['isfen']=!empty($count)?'已绑定设备':'未绑定设备'; //是否绑定设备
					$value['create']=$yunying->where('yid=%d',$value['founder'])->getField('companyname'); //运营商
				}
				
			}

			return $shops;
			
		}
}